/**
 * 初始化采集总量
 * showTotalCountTest--测试效果
 * showTotalCount--请求获取数据
 */
cqrbdp.showTotalCountTest = function() {
    var target = $("#totalcount"),
        endVal = 7922770996,
        queryState = true
        timeIntever = cqrbdp.totalFreshTimeInterval;

    var options = {
        useEasing: true, // toggle easing
        useGrouping: true, // 1,000,000 vs 1000000
        separator: '<span class="total-unit">万</span>', // character to use as a separator
        separator2: '<span class="total-unit">亿</span>',
        decimal: '.', // character to use as a decimal
    }
    var countup = new CountUp(target[0], 0, endVal, 0, 2, options);
    //当获得了初始数据后执行：
    countup.start();
    updateTotalCount();

    function updateTotalCount() {
        setTimeout(function() {
            endVal +=11225;
            countup.update(endVal);
            updateTotalCount();
        }, timeIntever);
    }
}

cqrbdp.showTotalCount = function() {
    var target = $("#totalcount"), //总量显示区域
        endVal, //显示值
        queryState = false, //是否可以进行下次查询
        countup,
        options = {
            useEasing: true, // toggle easing
            useGrouping: true, // 1,000,000 vs 1000000
            separator: '<span class="total-unit">万</span>', // character to use as a separator
            separator2: '<span class="total-unit">亿</span>',
            decimal: '.',
        },
        timeIntever = cqrbdp.totalFreshTimeInterval;; //查询时间间隔

    $.get('url', function(json) {
        endVal = json.result; //取值
        queryState = true;
        countup = new CountUp(target[0], 0, endVal, 0, 2, options);
        countup.start();
        setInterval(updateTotalCount, timeIntever);
    });

    function updateTotalCount() {
        if (!queryState) {
            return;
        }
        queryState = false;
        $.get('url', function(json) {
            endVal = json.result; //取值
            queryState = true;
            countup.update(endVal);
        })
    }

}


/**
 * 初始化分类统计总量
 *showFlStatisticsTest--测试效果
 *showFlStatistics--请求获取数据
 */
cqrbdp.showFlStatisticsTest = function() {
    var FlStatisticsItems = [{
        desc: "新浪微博",
        count: 502386291,
        icon: 'wb-icon'
    }, {
        desc: "腾讯微博",
        count: 7440000,
        icon: 'txwb-icon'
    }, {
        desc: "微信公众号",
        count: 236837506,
        icon: 'wx-icon'
    }, {
        desc: "新闻客户端",
        count: 242975,
        icon: 'khd-icon'
    }, {
        desc: "音视频",
        count: 272983053,
        icon: 'ysp-icon'
    }, {
        desc: "境外新闻",
        count: 134690,
        icon: 'xw-icon'
    }, {
        desc: "国内新闻",
        count: 193012810,
        icon: 'gnxw-icon'
    }, {
        desc: "国内博客",
        count: 33845140,
        icon: 'gnbk-icon'
    }, {
        desc: "国内论坛",
        count: 22874347,
        icon: 'gnlt-icon'
    }];

    var target = $("#flCount"), //数据显示区域
        endVal, //显示值
        queryState = false, //是否可以进行下次查询
        itemIndex = 0, //显示的序号
        countup,
        timeIntever = cqrbdp.flFreshTimeInterval; //查询时间间隔;

    var options = { //数据动态显示的配置信息
        useEasing: true, // toggle easing
        useGrouping: true, // 1,000,000 vs 1000000
        separator: '<span class="fl-unit">万</span>', // character to use as a separator
        separator2: '<span class="fl-unit">亿</span>',
        decimal: '.', // character to use as a decimal
    }

    $(".int-fl-item span").html(FlStatisticsItems[0].desc); //显示描述
    $(".int-fl-icon").find("." + FlStatisticsItems[0].icon).fadeIn("slow"); //显示图标
    //请求某分类统计量
    endVal = FlStatisticsItems[0].count;
    countup = new CountUp(target[0], 0, endVal, 0, 2, options);
    countup.start();
    queryState = true;
    setInterval(updateFlStatistics, timeIntever);

    function updateFlStatistics() {
        if (!queryState) {
            return;
        }
        queryState = false;

        var lastIndex = itemIndex;
        if (itemIndex < FlStatisticsItems.length - 1) {
            itemIndex += 1;
        } else {
            itemIndex = 0;
        }

        endVal = FlStatisticsItems[itemIndex].count;
        queryState = true;
        var desc = FlStatisticsItems[itemIndex].desc;
        var icon = FlStatisticsItems[itemIndex].icon;
        $(".int-fl-item span").html(desc);
        $(".int-fl-icon").find("." + FlStatisticsItems[lastIndex].icon).fadeOut("slow", function() {
            $(".int-fl-icon").find("." + FlStatisticsItems[itemIndex].icon).fadeIn("slow");
        });
        countup.update(endVal);
    }
}

cqrbdp.showFlStatistics = function() {
    var FlStatisticsItems = [{
        desc: "新浪微博",
        icon: 'wb-icon'
    }, {
        desc: "腾讯微博",
        icon: 'txwb-icon'
    }, {
        desc: "微信公众号",
        icon: 'wx-icon'
    }, {
        desc: "新闻客户端",
        icon: 'khd-icon'
    }, {
        desc: "音视频",
        icon: 'ysp-icon'
    },{
        desc: "境外新闻",
        icon: 'xw-icon'
    },
    {
        desc: "国内新闻",
        icon: 'gnxw-icon'
    },
    {
        desc: "国内博客",
        icon: 'gnbk-icon'
    },
    {
        desc: "国内论坛",
        icon: 'gnlt-icon'
    },];

    var target = $("#flCount"), //数据显示区域
        endVal, //显示值
        queryState = false, //是否可以进行下次查询
        itemIndex = 0, //显示的序号
        countup,
        timeIntever = cqrbdp.flFreshTimeInterval; //查询时间间隔;

    var options = { //数据动态显示的配置信息
        useEasing: true, // toggle easing
        useGrouping: true, // 1,000,000 vs 1000000
        separator: '<span class="fl-unit">万</span>', // character to use as a separator
        separator2: '<span class="fl-unit">亿</span>',
        decimal: '.', // character to use as a decimal
    }

    $(".int-fl-item span").html(FlStatisticsItems[0].desc); //显示描述
    $(".int-fl-icon").find("." + FlStatisticsItems[0].icon).fadeIn("slow"); //显示图标

    /**
     * 请求某分类统计量
     * 使用统计互联网采集分类数据总量接口
     *         参数直接使用itemIndex
     */
    $.get('url', {
        class: itemIndex
    }, function(json) {
        endVal = json.result;
        countup = new CountUp(target[0], 0, endVal, 0, 2, options);
        countup.start();
        queryState = true;
        setInterval(updateFlStatistics, timeIntever);
    });

    function updateFlStatistics() {
        if (!queryState) {
            return;
        }
        queryState = false;

        var lastIndex = itemIndex;
        if (itemIndex < FlStatisticsItems.length - 1) {
            itemIndex += 1;
        } else {
            itemIndex = 0;
        }

        $.get('url', '{data}', function(json) {
            endVal = json.result; //取值
            queryState = true;
            var desc = FlStatisticsItems[itemIndex].desc;
            var icon = FlStatisticsItems[itemIndex].icon;
            $(".int-fl-item span").html(desc);
            $(".int-fl-icon").find("." + FlStatisticsItems[lastIndex].icon).fadeOut("slow", function() {
                $(".int-fl-icon").find("." + FlStatisticsItems[itemIndex].icon).fadeIn("slow");
            });
            countup.update(endVal);
        });
    }
}
